 {extend name="v1/layout/base"}
 {block name="content"}
 <div class="layuimini-main">

   <fieldset class="table-search-fieldset xk-search-status" id="xk-search-status">
     <legend>搜索信息</legend>
     <div style="margin: 10px 10px 10px 10px">
       <div class="layui-row layui-col-space15">
         <div class="layui-col-md12">
           <form class="layui-form">
             <div class="layui-card-body layui-form layui-form-pane">
               <div class="layui-row layui-col-space10 layui-form-item">
                 <div class="layui-col-lg6">
                   <label class="layui-form-label">会员昵称/编号/手机号</label>
                   <div class="layui-input-block">
                     <input type="text" name="user_keywords" placeholder="会员号/昵称/手机号" id="user_keywords" class="layui-input">
                   </div>
                 </div>
                 <div class="layui-col-lg6">
                   <label class="layui-form-label">订单编号/快递单号/手机号</label>
                   <div class="layui-input-block">
                     <input type="text" name="keywords" placeholder="订单编号/快递单号/手机号/收货人姓名/地址" id="keywords" class="layui-input">
                   </div>
                 </div>
               </div>

               <div class="layui-row layui-col-space10 layui-form-item">
                 <div class="layui-col-lg6">
                   <label class="layui-form-label">订单来源</label>
                   <div class="layui-input-block">
                     <input type="checkbox" class="layui-input" lay-skin="primary" name="befrom" value="H5" title="微商城">
                     <input type="checkbox" class="layui-input" lay-skin="primary" name="befrom" value="app" title="APP">
                   </div>
                 </div>
                 <div class="layui-col-lg6">
                   <label class="layui-form-label">所属仓库</label>
                   <div class="layui-input-block">
                     {volist name="store_list" id="vo"}
                     <input type="checkbox" class="layui-input" lay-skin="primary" name="store_id" value="{$vo.store_id}" title="{$vo.store_name}">
                     {/volist}
                   </div>
                 </div>
               </div>
               <div class="layui-row layui-col-space10 layui-form-item">
                 <div class="layui-col-lg6">
                   <label class="layui-form-label">商品分类</label>
                   <div class="layui-input-block">
                     <select name="goods_cate_id" id="goods_cate_id" lay-search>
                       <option value="0">请选择商品分类</option>
                       {volist name="$goods_cate_list" id="vo"}
                       <option value="{$vo.goods_cate_id}">{$vo.goods_cate_name}</option>
                       {/volist}
                     </select>
                   </div>
                 </div>
                 <div class="layui-col-lg6">
                   <label class="layui-form-label">删除时间段</label>
                   <div class="layui-input-block">
                     <input type="text" class="layui-input" autocomplete="off" id="pay_time" placeholder="请选择对应的付款时间范围">
                   </div>
                 </div>
               </div>
               <div class="layui-row">
                 <div class="layui-col-xs4">&nbsp;</div>
                 <div class="layui-col-xs4">

                   <button type="reset" class="layui-btn layui-btn-primary  xk-refresh"><i class="fa fa-refresh"></i>&nbsp;重置</button>
                   <button type="button" class="layui-btn layui-btn-normal xk-dosearch">搜索<i class="layui-icon"></i></button>
                   <button type="button" class="layui-btn layui-btn-primary close-search"><i class="layui-icon">&#x1007;</i>关闭</button>
                 </div>
                 <div class="layui-col-xs4">&nbsp;</div>
               </div>
             </div>
           </form>

         </div>
       </div>
     </div>
   </fieldset>

   <script type="text/html" id="toolbar">
     <div class="layui-btn-container">
       <button class="layui-btn layui-btn-black  layui-btn-sm" lay-event="reseve"><i class="layui-icon">&#xe63d;</i></button>
       <div class="money_all"></div>
     </div>
   </script>

   <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

   <script type="text/html" id="currentTableBar">
     <button class="layui-btn layui-btn-radius layui-btn-warm layui-btn-sm" lay-event="show" data-url="/{:config('manage.manage_name')}/{:config('manage.version')}/Order/destroyorderShow"><i class="layui-icon">&#xe642;</i>查看&处理</button>
   </script>
   <!-- 图片 如果存在的话 -->
   <script type="text/html" id="picurlshow">
     <img src="{{d.horse_pic?d.horse_pic:'__COMMON__images/no_pic.png'}}" style="width:100px; height:100%" />
   </script>

 </div>
 {/block}
 {block name="myScript"}
 <script>
   layui.use(['form', 'table', 'laydate'], function() {
     var $ = layui.jquery,
       form = layui.form,
       table = layui.table;
     var laydate = layui.laydate;
     laydate.render({
       elem: '#pay_time',
       range: '~',
       theme: '#1E9FFF',
       type: 'datetime',
     });
     laydate.render({
       elem: '#receiving_time',
       range: '~',
       theme: '#1E9FFF',
       type: 'datetime',
     });
     table.render({
       elem: '#currentTableId',
       url: '/{:config("manage.manage_name")}/{:config("manage.version")}/Order/destroyList',
       toolbar: '#toolbar',
       defaultToolbar: ['filter', {
         title: '搜索',
         layEvent: 'search',
         icon: 'layui-icon-search'
       }],
       height: 'full-50',
       cols: [
         [{
             field: 'sub_order_sn',
             width: '10%',
             title: '订单编号'
           },
           {
             field: 'user_sn',
             width: '10%',
             title: '会员编号'
           },
           {
             field: 'user_name',
             width: '8%',
             title: '会员昵称'
           },
           {
             field: 'l_user_sn',
             width: '10%',
             title: '父级会员号'
           },
           {
             field: 'name',
             width: '8%',
             title: '收货人'
           },
           {
             field: 'tel',
             width: '8%',
             title: '电话'
           },
           {
             field: 'address',
             width: '10%',
             title: '收货地址'
           },
           {
             field: 'all_price',
             width: '8%',
             title: '订单总金额'
           },
           {
             field: 'status_txt',
             width: '8%',
             title: '订单状态'
           },
           {
             field: 'total_price',
             width: '8%',
             title: '商品总金额'
           },
           {
             field: 'total_freight',
             width: '8%',
             title: '运费金额'
           },
           {
             field: 'delete_time',
             width: '15%',
             title: '删除时间'
           },
           {
             field: 'refund_status',
             width: '8%',
             title: '售后状态'
           },
           {
             field: 'is_buy',
             width: '8%',
             title: '首购'
           },
           {
             field: 'pay_time',
             width: '15%',
             title: '付款时间'
           },
           {
             field: 'receiving_time',
             width: '15%',
             title: '收货时间'
           },
           {
             field: 'create_time',
             width: '15%',
             title: '下单时间'
           },
           {
             title: '操作',
             toolbar: '#currentTableBar',
             minWidth: '150',
             fixed: 'right',
             align: "center"
           }
         ]
       ],
       done: function (res, curr, count) {
         $(".money_all").html(res.resultData.show_count);
       },
       limits: [100, 150, 200, 250, 500, 1000],
       limit: 100,
       id: 'table_ids',
       page: true,
       skin: 'line'
     });
     // 顶部操作工具
     table.on('toolbar(currentTableFilter)', function(obj) {
       var url = $(this).attr('data-url'),
         id_arr = getCheckValue();
       switch (obj.event) {
         case 'reseve':
           table.reload('table_ids');
           break;
         case 'export':
           var user_keywords = $("#user_keywords").val(),
             keywords = $("#keywords").val(),
             pay_type = '',
             pay_type_arr = [],
             status = '',
             status_arr = [],
             refund_status = '',
             refund_status_arr = [],
             befrom = '',
             befrom_arr = [],
             shipping_type = '',
             shipping_type_arr = [],
             store_id = '',
             store_id_arr = [],
             goods_cate_id = $("#goods_cate_id").val(),
             pay_time = $("#pay_time").val(),
             receiving_time = $("#receiving_time").val();
           $("input[name=pay_type]:checked").each(function() {
             pay_type_arr.push($(this).val());
           });
           pay_type = pay_type_arr.join(',');
           $("input[name=status]:checked").each(function() {
             status_arr.push($(this).val());
           });
           status = status_arr.join(',');
           $("input[name=refund_status]:checked").each(function() {
             refund_status_arr.push($(this).val());
           });
           refund_status = refund_status_arr.join(',');
           $("input[name=befrom]:checked").each(function() {
             befrom_arr.push($(this).val());
           });
           befrom = befrom_arr.join(',');
           $("input[name=shipping_type]:checked").each(function() {
             shipping_type_arr.push($(this).val());
           });
           shipping_type = shipping_type_arr.join(',');
           $("input[name=store_id]:checked").each(function() {
             store_id_arr.push($(this).val());
           });
           store_id = store_id_arr.join(',');
           var url = "/{:config('manage.manage_name')}/{:config('manage.version')}/Order/exportOrder";
           https(url, {
             user_keywords: user_keywords,
             keywords: keywords,
             pay_type: pay_type,
             status: status,
             refund_status: refund_status,
             befrom: befrom,
             shipping_type: shipping_type,
             store_id: store_id,
             goods_cate_id: goods_cate_id,
             pay_time: pay_time,
             receiving_time: receiving_time
           }, 'post', true, '正在执行订单数据导出').then(res => {
             if (res.result_code == 200) {
               var html = '<h1 style="padding: 0 20px;color:red;font-size:18px;margin-bottom:15px;">如果据量大于1万条系统自动分表导出</h1>';
               res.resultData.forEach(function(value, index) {
                 html += '<h2 style="padding: 0 20px;font-size:16px;">第' + (index + 1) + '个订单文件：<a href="' + value + '">' + '下载' + '</a></h2>';
               })
               layer.open({
                 type: 1,
                 skin: 'layui-layer-rim', //加上边框
                 area: ['400px', '200px'], //宽高
                 content: html
               });
             }
           })
           break;
         case 'exportWaitShipping':
             var user_keywords = $("#user_keywords").val(),
               keywords = $("#keywords").val(),
               pay_type = '',
               pay_type_arr = [],
               status = '',
               status_arr = [],
               refund_status = '',
               refund_status_arr = [],
               befrom = '',
               befrom_arr = [],
               shipping_type = '',
               shipping_type_arr = [],
               store_id = '',
               store_id_arr = [],
               goods_cate_id = $("#goods_cate_id").val(),
               pay_time = $("#pay_time").val(),
               receiving_time = $("#receiving_time").val();
             $("input[name=pay_type]:checked").each(function() {
               pay_type_arr.push($(this).val());
             });
             pay_type = pay_type_arr.join(',');
             $("input[name=status]:checked").each(function() {
               status_arr.push($(this).val());
             });
             status = status_arr.join(',');
             $("input[name=refund_status]:checked").each(function() {
               refund_status_arr.push($(this).val());
             });
             refund_status = refund_status_arr.join(',');
             $("input[name=befrom]:checked").each(function() {
               befrom_arr.push($(this).val());
             });
             befrom = befrom_arr.join(',');
             $("input[name=shipping_type]:checked").each(function() {
               shipping_type_arr.push($(this).val());
             });
             shipping_type = shipping_type_arr.join(',');
             $("input[name=store_id]:checked").each(function() {
               store_id_arr.push($(this).val());
             });
             store_id = store_id_arr.join(',');
             var url = "/{:config('manage.manage_name')}/{:config('manage.version')}/Order/exportWaitShipping";
             https(url, {
               user_keywords: user_keywords,
               keywords: keywords,
               pay_type: pay_type,
               status: status,
               refund_status: refund_status,
               befrom: befrom,
               shipping_type: shipping_type,
               store_id: store_id,
               goods_cate_id: goods_cate_id,
               pay_time: pay_time,
               receiving_time: receiving_time
             }, 'post', true, '正在执行订单数据导出').then(res => {
               if (res.result_code == 200) {
                 var html = '<h1 style="padding: 0 20px;color:red;font-size:18px;margin-bottom:15px;">如果据量大于1万条系统自动分表导出</h1>';
                 res.resultData.forEach(function(value, index) {
                   html += '<h2 style="padding: 0 20px;font-size:16px;">第' + (index + 1) + '个订单文件：<a  href="' + value + '">' + '下载' + '</a></h2>';
                 })
                 layer.open({
                   type: 1,
                   skin: 'layui-layer-rim', //加上边框
                   area: ['400px', '200px'], //宽高
                   content: html
                 });
               }
             })
           break;
         case 'importWaitShipping':
           var url = "/{:config('manage.manage_name')}/{:config('manage.version')}/Order/importWaitShipping";
           var user_keywords = $("#user_keywords").val(),
             keywords = $("#keywords").val(),
             pay_type = '',
             pay_type_arr = [],
             status = '',
             status_arr = [],
             refund_status = '',
             refund_status_arr = [],
             befrom = '',
             befrom_arr = [],
             shipping_type = '',
             shipping_type_arr = [],
             store_id = '',
             store_id_arr = [],
             goods_cate_id = $("#goods_cate_id").val(),
             pay_time = $("#pay_time").val(),
             receiving_time = $("#receiving_time").val();
           $("input[name=pay_type]:checked").each(function() {
             pay_type_arr.push($(this).val());
           });
           pay_type = pay_type_arr.join(',');
           $("input[name=status]:checked").each(function() {
             status_arr.push($(this).val());
           });
           status = status_arr.join(',');
           $("input[name=refund_status]:checked").each(function() {
             refund_status_arr.push($(this).val());
           });
           refund_status = refund_status_arr.join(',');
           $("input[name=befrom]:checked").each(function() {
             befrom_arr.push($(this).val());
           });
           befrom = befrom_arr.join(',');
           $("input[name=shipping_type]:checked").each(function() {
             shipping_type_arr.push($(this).val());
           });
           shipping_type = shipping_type_arr.join(',');
           $("input[name=store_id]:checked").each(function() {
             store_id_arr.push($(this).val());
           });
           store_id = store_id_arr.join(',');
           var index = layer.open({
             title: '物流信息回传处理',
             type: 2,
             shade: 0.2,
             maxmin: true,
             shadeClose: true,
             area: ['80%', '80%'],
             content: url,
             cancel: function() {
               table.reload('table_ids', {
                 where: {
                   user_keywords: user_keywords,
                   keywords: keywords,
                   pay_type: pay_type,
                   status: status,
                   refund_status: refund_status,
                   befrom: befrom,
                   shipping_type: shipping_type,
                   store_id: store_id,
                   goods_cate_id: goods_cate_id,
                   pay_time: pay_time,
                   receiving_time: receiving_time
                 }
               });
             }
           });
            break;
         case 'search':
           $("#xk-search-status").removeClass('xk-search-status');
           break;
       }
     })
     // 列表工具栏目
     table.on('tool(currentTableFilter)', function(obj) {
       var data = obj.data,
         event = obj.event,
         url = $(this).attr('data-url');
       url = url + '/sub_order_sn/' + data.sub_order_sn;
       var user_keywords = $("#user_keywords").val(),
         keywords = $("#keywords").val(),
         pay_type = '',
         pay_type_arr = [],
         status = '',
         status_arr = [],
         refund_status = '',
         refund_status_arr = [],
         befrom = '',
         befrom_arr = [],
         shipping_type = '',
         shipping_type_arr = [],
         store_id = '',
         store_id_arr = [],
         goods_cate_id = $("#goods_cate_id").val(),
         pay_time = $("#pay_time").val(),
         receiving_time = $("#receiving_time").val();
       $("input[name=pay_type]:checked").each(function() {
         pay_type_arr.push($(this).val());
       });
       pay_type = pay_type_arr.join(',');
       $("input[name=status]:checked").each(function() {
         status_arr.push($(this).val());
       });
       status = status_arr.join(',');
       $("input[name=refund_status]:checked").each(function() {
         refund_status_arr.push($(this).val());
       });
       refund_status = refund_status_arr.join(',');
       $("input[name=befrom]:checked").each(function() {
         befrom_arr.push($(this).val());
       });
       befrom = befrom_arr.join(',');
       $("input[name=shipping_type]:checked").each(function() {
         shipping_type_arr.push($(this).val());
       });
       shipping_type = shipping_type_arr.join(',');
       $("input[name=store_id]:checked").each(function() {
         store_id_arr.push($(this).val());
       });
       store_id = store_id_arr.join(',');
       switch (event) {
         case 'show':
           var index = layer.open({
             title: '订单' + data.sub_order_sn + '查看&处理',
             type: 2,
             shade: 0.2,
             maxmin: true,
             shadeClose: true,
             area: ['100%', '100%'],
             content: url,
             cancel: function() {
               table.reload('table_ids', {
                 where: {
                   user_keywords: user_keywords,
                   keywords: keywords,
                   pay_type: pay_type,
                   status: status,
                   refund_status: refund_status,
                   befrom: befrom,
                   shipping_type: shipping_type,
                   store_id: store_id,
                   goods_cate_id: goods_cate_id,
                   pay_time: pay_time,
                   receiving_time: receiving_time
                 }
               });
             }
           });
           break;
       }
     })
     // 执行搜索
     $(".xk-dosearch").click(function() {
       var user_keywords = $("#user_keywords").val(),
         keywords = $("#keywords").val(),
         pay_type = '',
         pay_type_arr = [],
         status = '',
         status_arr = [],
         refund_status = '',
         refund_status_arr = [],
         befrom = '',
         befrom_arr = [],
         shipping_type = '',
         shipping_type_arr = [],
         store_id = '',
         store_id_arr = [],
         goods_cate_id = $("#goods_cate_id").val(),
         pay_time = $("#pay_time").val(),
         receiving_time = $("#receiving_time").val();
       $("input[name=pay_type]:checked").each(function() {
         pay_type_arr.push($(this).val());
       });
       pay_type = pay_type_arr.join(',');
       $("input[name=status]:checked").each(function() {
         status_arr.push($(this).val());
       });
       status = status_arr.join(',');
       $("input[name=refund_status]:checked").each(function() {
         refund_status_arr.push($(this).val());
       });
       refund_status = refund_status_arr.join(',');
       $("input[name=befrom]:checked").each(function() {
         befrom_arr.push($(this).val());
       });
       befrom = befrom_arr.join(',');
       $("input[name=shipping_type]:checked").each(function() {
         shipping_type_arr.push($(this).val());
       });
       shipping_type = shipping_type_arr.join(',');
       $("input[name=store_id]:checked").each(function() {
         store_id_arr.push($(this).val());
       });
       store_id = store_id_arr.join(',');
       table.reload('table_ids', {
         page: {
           curr: 1
         },
         where: {
           user_keywords: user_keywords,
           keywords: keywords,
           pay_type: pay_type,
           status: status,
           refund_status: refund_status,
           befrom: befrom,
           shipping_type: shipping_type,
           store_id: store_id,
           goods_cate_id: goods_cate_id,
           pay_time: pay_time,
           receiving_time: receiving_time
         }
       }, 'data');
     })
     // 获取选中项
     function getCheckValue() {
       var id_arr = [],
         id_str = '';
       var checkStatus = table.checkStatus('table_ids'),
         data = checkStatus.data;
       data.map(function(d) {
         id_arr.push(d.shipping_id);
       })
       id_str = id_arr.join(',');
       return id_str;
     }
   });
 </script>
 {/block}
